﻿ 
<!DOCTYPE html>  
<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <meta name="keywords" content="公司员工">  
    <meta name="description" content="公司员工">  
    <title>公司员工管理</title>  
    
    <%@ include file="/WEB-INF/inc/default.jsp"%>
    <jsp:include page="/WEB-INF/inc/dic.jsp"/>

</head>  
<body>  
    
      
   <div class="easyui-layout" style="height:550px;">
   	   <div data-options="region:'west',split:true" title="" style="width:300px;">
   	       <table id="dg_dic_category" title="类别管理" style="height:520px"  
                url="/sysadmin/systemDicCategory/list.do"  
                toolbar="#toolbar_dic_category" pagination="true"  data-options="pageSize:2" 
                rownumbers="true" fitColumns="true" loadMsg="正在查询,请稍候..." singleSelect="true">  
           
           </table> 
   	   </div>
       <div data-options="region:'center',title:'',iconCls:'icon-ok'">
       	    <table id="dg_dic" title="字典管理" style="height:520px"  
                url="/sysadmin/systemDic/list.do"  
                toolbar="#toolbar_dic" pagination="true"  
                rownumbers="true" fitColumns="true" loadMsg="正在查询,请稍候..." singleSelect="true">  

            </table>  
       </div>    	
   </div>  

    <div id="toolbar_dic_category">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_dic_category()">新增</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit_dic_category()">修改</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deletes_dic_category()">删除</a>          
    </div> 
    <div id="toolbar_dic">  
    	  <div>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_dic()">新增</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit_dic()">修改</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deletes_dic()">删除</a>  
        
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="find()">查询</a>
        
        <a href="javascript:void(0)" id="childbutton"  disabled="true" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="down_dic()">下一级</a>        
        <a href="javascript:void(0)" id="parentbutton" disabled="true" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="up_dic()">上一级</a>
      </div>
       <div>
       	   上级：<input disabled="true"  style="width:300px" id="parentdic" name="parentdic" class="easyui-box">
       </div>
    </div> 
    <div id="dlg_dic_category" class="easyui-dialog" style="width:600px;height:280px;padding:10px 20px"  
            closed="true" buttons="#dlg_dic_category-buttons">
        
        <form id="fm_dic_category" method="post" novalidate>  
        	  	  	 <input type="hidden" name="id" > 
	        		     <div class="fitem">  
                     <label style="width:100px">类别<font color="red">*</font>:</label>                                            
                     <input  name="category" class="easyui-box" required="true">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">名称<font color="red">*</font>:</label>                                            
                     <input name="name" class="easyui-box" required="true">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">层级:</label>                       
                     <input name="level" class="easyui-numberbox">                       
                   </div>	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">remark:</label>                                            
                     <input name="remark" class="easyui-box">                       
                   </div> 	        		          		     
        </form>          
        
    </div>  
    <div id="dlg_dic" class="easyui-dialog" style="width:500px;height:350px;"  
            closed="true" buttons="#dlg_dic-buttons">  
        <form id="fm_dic" method="post" novalidate>  
        	  	  	 
        	  	  	 <input type="hidden" name="category" >
        	  	  	 <input type="hidden" name="parentId" >
        	  	  	 <input type="hidden" name="parentIds" >
        	  	  	 <div class="fitem">  
                     <label style="width:100px">分类:</label>                                            
                     <input  name="categoryName" disabled="true" class="easyui-box">                       
                   </div>         	  	  	 
        	  	  	 <div divItemId="parentName" class="fitem">  
                     <label style="width:100px">上级:<font color="red">*</font>:</label>                       
                     <input  name="parentName" disabled="true" class="easyui-box easyui-validatebox" >                       
                   </div>
	        		     <div class="fitem">  
                     <label style="width:100px">编号<font color="red">*</font>:</label>                                            
                     <input  name="id" class="easyui-numberbox"  required="true" >                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">中文名<font color="red">*</font>:</label>                                            
                     <input name="codeNameCn" class="easyui-box easyui-validatebox"  required="true">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">英文名:</label>                                            
                     <input name="codeNameEn" class="easyui-box">                       
                   </div> 	        		     	        		     	        		     
	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">排序:</label>                       
                     <input name="seqNo" class="easyui-numberbox">                       
                   </div>	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">状态：<font color="red">*</font>:</label>                                            
                     
                     <input class="easyui-combobox"  required="true" name="status" style="width:200px;"  data-options="data:__getConstantCategory('DIC_STATUS'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' ">                     
                   </div> 
	        		     
        </form>  
    </div>    
     <div id="dlg_query" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"  
            closed="true" buttons="#dlg-buttons-query">  
        <div class="ftitle">系统字典</div>  
        <form id="fm_query" method="post" novalidate>  
                   <input type="hidden" value="0" name="parentId" >
	        		     <div class="fitem">  
                     <label style="width:100px">分类:</label>                                                                 
                     <input class="easyui-combobox" itemId="category"  name="category" style="width:200px;"  data-options="url:'/sysadmin/systemDicCategory/categoryList.do',valueField:'category', textField:'name', multiple:false,panelHeight:'auto',mode:'remote' ">                     
                   </div>
	        		     <div class="fitem">  
                     <label style="width:100px">中文名:</label>                                            
                     <input name="codeNameCn" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">英文名:</label>                                            
                     <input name="codeNameEn" class="easyui-box">                       
                   </div> 	        		      	        		         
	        		     <div class="fitem">  
                     <label style="width:100px">状态:</label>                                                                 
                     <input class="easyui-combobox" itemId="status"  name="status" style="width:200px;"  data-options="data:__getConstantCategory('DIC_STATUS'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' ">                                        
                   </div> 
	        		       		                   
              
        </form>  
    </div> 
    <div id="dlg_dic-buttons" style="text-align:center">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_dic()">Save</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg_dic').dialog('close')">关闭</a>  
    </div> 
    <div id="dlg-buttons-query" style="text-align:center">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="query()">查询</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg_query').dialog('close')">关闭</a>  
    </div>     
    </div>    
        <div id="dlg_dic_category-buttons" style="text-align:center">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_dic_category()">Save</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg_dic_category').dialog('close')">关闭</a>  
    </div> 
   <script type="text/javascript"> 
   	  var curCategory='';
   	  var totalLevel=1;
   	  var curLevel=1;
   	  var curCategoryName='';
   	  var curParentId=0;
   	  var curParentName='无';
   	  
   	  function add_dic_category(){         	 
            $('#dlg_dic_category').dialog('open').dialog('setTitle','新增类别');  
            $('#fm_dic_category').form('clear');  
            url = '/sysadmin/systemDicCategory/save.do';  
        }  
        function edit_dic_category(){  
            //var row = $('#dg').datagrid('getSelected');  
            var rows = $('#dg_dic_category').datagrid('getSelections');
            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要修改的行','info');
            	 return;
            }
            if (!rows||rows.length>1){
            	 $.messager.alert('提示','不能选择多行','info');
            	 return;
            }
            if (rows){  
                $('#dlg_dic_category').dialog('open').dialog('setTitle','修改类别');  
                
                $('#fm_dic_category').form('load','/sysadmin/systemDicCategory/get.do?id='+rows[0].id);  
                url = '/sysadmin/systemDicCategory/update.do';
            }  
        }  
        function save_dic_category(){          	   
        	  if (!$('#fm_dic_category').form('validate')) return; 
            $('#fm_dic_category').form('submit',{  
                url: url,  
                onSubmit: function(){  
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');                      
                    if (result.success == true){  
                        $.messager.alert('信息',result.msg,'info');  
                        $('#dlg_dic_category').dialog('close');      // close the dialog  
                        $('#dg_dic_category').datagrid('reload');    // reload the user data  
                    } else {  
                        $.messager.alert('错误',result.msg,'error');
                    }  
                }  
            });  
        } 
   	
   	   function add_dic(){         	
   	   	   if (curCategory==''){
   	   	   	  $.messager.alert('信息','请选定类别','info');  
   	   	   	  return;
   	   	   }	 
   	   	   //if (parentId=0) parentIds=$('#fm_dic').find('input[name="parentIds"]').attr("value",'0');
   	   	   
   	   	   
   	   	   
   	   	   //
   	   	   $('#fm_dic').form('clear');  
   	   	   $('#fm_dic').find('input[name="parentIds"]').attr("value",'0');
   	   	   $('#fm_dic').find('input[name="categoryName"]').attr("value",curCategoryName);   	   	        
   	   	   $('#fm_dic').find('input[name="parentName"]').attr("value",curParentName);
   	   	   
   	   	   $('#fm_dic').find('input[name="category"]').attr("value",curCategory);
   	   	   
   	   	   
   	   	   
   	   	   $('#fm_dic').find('input[name="parentId"]').attr("value",curParentId);
   	   	   
   	   	   
   	   	   //设置查询为当前的category
   	   	   $('#fm_query').find('input[itemId="category"]').combobox("setValue",curCategory);
            $('#dlg_dic').dialog('open').dialog('setTitle','新增系统字典');  
            
            url = '/sysadmin/systemDic/save.do';  
        }  
        function setDicButton(){
        	 if (totalLevel>curLevel){        	  	
        	  	$('#childbutton').linkbutton("enable"); 
        	  	
        	  	if (curLevel>1)
        	  	   $('#parentbutton').linkbutton("enable"); 
        	  	else $('#parentbutton').linkbutton("disable");
        	  	
        	  }else if (totalLevel=curLevel){
        	  	$('#childbutton').linkbutton("disable");
        	  	if (totalLevel>1)
        	  	   $('#parentbutton').linkbutton("enable"); 
        	  	else    
        	  		$('#parentbutton').linkbutton("disable");
        	  	
        	  	
        	  	
        	  }
        	  $('#parentdic').attr("value",curParentName);
        	  
        }	
        function child_dic(pId,pName){  
        	  if (totalLevel<=curLevel){
        	  	
        	  	return;
        	  } 
        	  
        	  curLevel=curLevel+1;
        	  
        	 
        	  
        	  //设置当前的id为parentId
        	  curParentId=pId;
        	  curParentName=pName;
        	   setDicButton();	
        	  $('#fm_query').find('input[name="parentId"]').attr("value",curParentId); 
        	  query();
        }
        function parent_dic(pId,pName){
        	  
        	  if (curLevel==1){        	  	
        	  	
        	  	return;
        	  }
        	  
        	  curLevel=curLevel-1;
        	  
        	  
        	  
        	  curParentId=pId;
        	  curParentName=pName;
        	  setDicButton();	
        	  $('#fm_query').find('input[name="parentId"]').attr("value",curParentId); 
        	  query();
        }	
         function down_dic(){  
            
            var rows = $('#dg_dic').datagrid('getSelections');
            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择父分类','info');
            	 return;
            }
            if (!rows||rows.length>1){
            	 $.messager.alert('提示','不能选择多个父分类','info');
            	 return;
            }
            if (rows){  
                
                
                child_dic(rows[0].id,rows[0].codeNameCn);
                
            }  
        }  
        function up_dic(){  
            
            $.post('/sysadmin/systemDic/getParent.do',{id:curParentId},function(result){  
                            if (result.success){  
                            	  
                            	  
                                parent_dic(result.data.id,result.data.codeNameCn);
                            } else {  
                                 
                                $.messager.alert('错误',result.errorMsg,'error'); 
                            }  
                        },'json');  
        }  
        function edit_dic(){  
            //var row = $('#dg').datagrid('getSelected');  
            var rows = $('#dg_dic').datagrid('getSelections');
            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要修改的行','info');
            	 return;
            }
            if (!rows||rows.length>1){
            	 $.messager.alert('提示','不能选择多行','info');
            	 return;
            }
            if (rows){  
                $('#dlg_dic').dialog('open').dialog('setTitle','修改系统字典');  
                //$('#fm').form('load',rows[0]);  
                $('#fm_dic').form('load',rows[0]);  
                
                
   	   	        $('#fm_dic').find('input[name="categoryName"]').attr("value",curCategoryName);   	   	        
   	   	        $('#fm_dic').find('input[name="parentName"]').attr("value",curParentName);
                
                
                //$('#fm_dic').form('load','/sysadmin/systemDic/get.do?id='+rows[0].id);  
                url = '/sysadmin/systemDic/update.do';
            }  
        }  
        function find(){  
              
                $('#dlg_query').dialog('open').dialog('setTitle','查询');  
                
                url = '/sysadmin/systemDic/list.do';  
              
        } 
         function query(){  
                                
                var formdata=$('#fm_query').formToArray();                
                
                if (!$('#fm_query').form('validate')) return; 
               
                $('#dg_dic').datagrid({
	                  queryParams: array2json(formdata)
                });
                
               $('#dlg_query').dialog('close');
               
              
        }
        function save_dic(){          	   
        	  if (!$('#fm_dic').form('validate')) return; 
            $('#fm_dic').form('submit',{  
                url: url,  
                onSubmit: function(){  
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');                      
                    if (result.success == true){  
                        $.messager.alert('信息',result.msg,'info');  
                        $('#dlg_dic').dialog('close');      // close the dialog  
                        $('#dg_dic').datagrid('reload');    // reload the user data  
                    } else {  
                        $.messager.alert('错误',result.msg,'error');
                    }  
                }  
            });  
        } 
   	   $('#dg_dic_category').datagrid({
   	   	     pageSize:20,
        	   columns:[[
        	   	
        	   	   {field:'category',title:'分类编码', width:100}
        	   	   ,{field:'name',title:'名称', width:100}
        	   	   ,{field:'level',title:'层级', width:100}        	   	   
        	   	
        	   	
        	   ]]
        	   ,onDblClickRow: function(rowIndex, rowData){
        	    	$('#dlg_dic_category').dialog('open').dialog('setTitle','修改类别');                  
                $('#fm_dic_category').form('load','/sysadmin/systemDicCategory/get.do?id='+rowData.id);  
                url = '/sysadmin/systemDicCategory/update.do';        	    	
        	    }
        	    ,onClickRow: function(rowIndex, rowData){
        	    	   //var ps={'category':rowData.category};
                   //$('#dg_dic').datagrid({
	                  //  queryParams: ps 
                   //});      	    	
                   //$('#dg_dic').datagrid('reload');
                   //curCategory=rowData.category;       
                               
                   $('#fm_query').find('input[itemId="category"]').combobox("setValue",rowData.category);
                   //初始化
                   $('#fm_query').find('input[itemId="status"]').combobox("setValue",null);
                   $('#fm_query').find('input[name="codeNameCn"]').attr("value",''); 
                   $('#fm_query').find('input[name="parentId"]').attr("value",'0'); 
                   $('#fm_query').find('input[name="codeNameEn"]').attr("value",''); 
                   
                   curCategoryName=rowData.name;
                   curCategory=rowData.category;
   	               curParentId=0;
   	               curLevel=1;
   	               totalLevel=rowData.level;
   	               
   	               /*
   	               if(totalLevel>1){
   	               	   	               	
   	               	 $('#childbutton').linkbutton("enable"); 
   	               	
   	               }	 
   	               else $('#childbutton').linkbutton("disable"); 
   	               	
   	               $('#parentbutton').linkbutton("disable"); 
   	               */
   	               curParentName='无';
   	               setDicButton();
   	               query();
   	               
   	               
        	    }
        }); 
        
       $('#dg_dic').datagrid({
       	    pageSize:20,
        	   columns:[[
        	   	
        	   	   {field:'id',title:'编号', width:100}
        	   	   ,{field:'category',title:'分类', width:100}
        	   	   ,{field:'codeNameCn',title:'中文名', width:100}
        	   	   ,{field:'codeNameEn',title:'英文名', width:100}        	   	   
        	   	   ,{field:'parentName',title:'上级', width:100}        	   	  
        	   	   ,{field:'seqNo',title:'排序', width:100}
        	   	   ,{field:'status',title:'状态', width:100
        	   	   	,formatter: function(value,row,index){
        	   		      	return __getConstantCategoryCodeValue('DIC_STATUS', value);
        	   		      }
        	   	   	}
        	   	   
        	   	
        	   	
        	   ]]
        	   ,onDblClickRow: function(rowIndex, rowData){
        	    	//$('#dlg_dic').dialog('open').dialog('setTitle','修改系统字典');                  
                //$('#fm_dic').form('load','/sysadmin/systemDic/get.do?id='+rowData.id);  
                //url = '/sysadmin/systemDic/update.do';        	    	
                child_dic(rowData.id,rowData.codeNameCn)
        	    }
        	    ,queryParams:{'category':'NULL'}
        });   
   </script>	   
     
     
</body>  
</html>